import {createStore} from 'vuex'

export default createStore({
    state: {
        // 菜单
        menus: [],
        // 权限
        perms: JSON.parse(sessionStorage.getItem('perms') || '[]'),
        // 昵称
        nick: sessionStorage.getItem('nick') || '',
        // 头像
        avatar: sessionStorage.getItem('avatar') || '',
    },
    getters: {},
    mutations: {
        setMenus(state, menus) {
            state.menus = menus
        },
        setPerms(state, perms) {
            state.perms = perms
            sessionStorage.setItem('perms', JSON.stringify(perms))
        },
        setNick(state, nick) {
            state.nick = nick
            sessionStorage.setItem('nick', nick)
        },
        setAvatar(state, avatar) {
            state.avatar = avatar
            sessionStorage.setItem('avatar', avatar)
        },
        resetState(state) {
            state.menus = []
            state.perms = []
            state.nick = ''
            state.avatar = ''
        }
    },
    actions: {},
    modules: {}
})
